package com.itheima.demo07.Prop;

import java.io.*;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class Demo01Properties {
    public static void main(String[] args) throws IOException {
//        show01();
//        show02();
        show03();
    }

    public static void show01() {
        Properties prop = new Properties();
        prop.setProperty("赵丽颖", "168");
        prop.setProperty("迪丽热巴", "165");
        prop.setProperty("古力娜扎", "160");
        Set<String> set = prop.stringPropertyNames();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String key = it.next();
            String value = prop.getProperty(key);
            System.out.println(key + ":" + value);
        }
    }

    public static void show02() throws IOException {
        Properties prop = new Properties();
        prop.setProperty("赵丽颖", "168");
        prop.setProperty("迪丽热巴", "165");
        prop.setProperty("古力娜扎", "160");
        /*FileWriter fw = new FileWriter("day09_IOAndProperties\\prop.txt");
        prop.store(fw, "save data");
        fw.close();*/
        prop.store(new FileOutputStream("day09_IOAndProperties\\prop2.txt"), "");
    }

    public static void show03() throws IOException {
        Properties prop = new Properties();
        FileReader fr = new FileReader("day09_IOAndProperties\\prop.txt");
//        FileInputStream fis = new FileInputStream("day09_IOAndProperties\\prop.txt");
        prop.load(fr);
//        prop.load(fis);
        Set<String> set = prop.stringPropertyNames();
        for (String key : set) {
            String value = prop.getProperty(key);
            System.out.println(key + ":" + value);
        }
    }
}
